def isPrime(num):
        if num <= 1:
              return False
        for i in range(2, num):
               if num % i == 0:
                   return False
        return True


print("Введите четырёхзначное число:")
num=int(input())
if 999<num<10000:
        a=num
        b=num//10
        c=num//1000
        d=num//100
        e=num%1000//10
        f=num//100
        g=num//1000
        h=num//100%10
        i=num//10%100
        j=num%1000
        lst =[a, b, c, d, e, f, g, h, i, j]
        sre=0
        for n in lst:
                if isPrime(n):
                        sre =max(sre, n)
        print (sre)
else:
        print(0)
        
        
        
        
    


